package cn.yu.takeoutbackend.fileManagement.controller;

import cn.yu.takeoutbackend.common.Result;
import cn.yu.takeoutbackend.fileManagement.service.FileManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.Path;

@RestController()
@RequestMapping("/fileManagement")
@Slf4j
public class FileManagementController {

    @Autowired
    @Qualifier("fileManagementServiceImpl")
    private FileManagementService fileService;


    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestParam("file") MultipartFile file) {
        log.info("----------------  uploadFile start ----------------");
        log.info("uploadFile: {}", file);
        try {
            final String fileId = fileService.updateFile(file);
            return Result.success("添加成功").setResultData(fileId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        } finally {
            log.info("----------------  uploadFile end ----------------");
        }
    }
}
